package com.example.random_your_hero.controller;

import com.example.random_your_hero.model.Hero;
import com.example.random_your_hero.service.IHeroService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/hero")
public class HeroController {

    @Autowired
    IHeroService heroService;

    @GetMapping("/list")
    public List<Hero> getList(){
        return heroService.getList();
    }

    @GetMapping("/random/{number}")
    public List<Hero> getRandomList(@PathVariable(name = "number") String number){
        return heroService.getRandomList(number);
    }

    @PostMapping("/add")
    public String add(@RequestBody Hero hero){
        return heroService.add(hero);
    }

    @GetMapping("/searchById/{id}")
    public Map<String, Object> searchById(@PathVariable(name = "id") String id){
        return heroService.searchById(id);
    }

    @PostMapping("/update")
    public String update(@RequestBody Hero hero){
        return heroService.updateById(hero);
    }

    @PostMapping("/updateById")
    public String updateById(@RequestBody Hero hero){
        return heroService.updateById(hero);
    }

    @PostMapping("/delete")
    public String delete(HttpServletRequest httpServletRequest){
        return heroService.deleteById(httpServletRequest);
    }


}
